package com.bdk.middle.tenant.web;


import com.bdk.middle.common.domain.PageDO;
import com.bdk.middle.common.result.ResultDO;
import com.bdk.middle.common.result.web.ObjectResponse;
import com.bdk.middle.tenant.api.domain.TenantPermissionDO;
import com.bdk.middle.tenant.api.query.TenantPermissionQueryDO;
import com.bdk.middle.tenant.service.TenantPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 用户登录表 前端控制器
 * </p>
 *
 * @author Reagan
 * @since 2021-01-23
 */
@Api(tags = "权限管理相关接口")
@RestController
@RequestMapping("/TenantPermission_permission")
public class TenantPermissionController {

    @Autowired
    private TenantPermissionService tenantPermissionService;
    @ApiOperation(value="权限管理新增", notes="权限管理新增")
    @RequestMapping(value="/add.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse add(@RequestBody TenantPermissionDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantPermissionService.add(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="权限管理编辑", notes="权限管理编辑")
    @RequestMapping(value="/edit.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse edit(@RequestBody TenantPermissionDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantPermissionService.edit(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="权限管理删除", notes="权限管理删除")
    @RequestMapping(value="/delete.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse delete(@RequestBody TenantPermissionDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantPermissionService.remove(domain.getId(), null);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="权限管理详情", notes="权限管理详情")
    @RequestMapping(value="/detail.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse detail(@RequestBody TenantPermissionDO domain) {

        ObjectResponse<TenantPermissionDO> response = new ObjectResponse();

        ResultDO result = tenantPermissionService.get(domain.getId());

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        } else {
            response.setData((TenantPermissionDO) result.getModel(ResultDO.FIRST_MODEL_KEY));
        }
        return response;
    }
    @ApiOperation(value="权限管理列表", notes="权限管理列表")
    @RequestMapping(value="/list.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse list(@RequestBody TenantPermissionQueryDO domain) {

        ObjectResponse<PageDO<TenantPermissionDO>> response = new ObjectResponse();

        ResultDO result = tenantPermissionService.find(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        } else {
            response.setData((PageDO<TenantPermissionDO>) result.getModel(ResultDO.FIRST_MODEL_KEY));
        }
        return response;
    }

}

